<?php

$in = "";
$str = "";
for ($i = 1; $i < $argc; $i++) {
    echo $argv[$i] . PHP_EOL;
    $str .= file_get_contents($argv[$i]);
}
$str = mb_convert_encoding($str, 'UTF-8', 'GBK,GB2312');

$kong = array(" ", "　", "\t", "\n", "\r", PHP_EOL);
$fuhao = '。，？【】＼、‘’“”：*！《》；１２３４５６７８９０［］｛｝|-·～＠＃￥％……＆×（）——＋1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
';
$fuhao .= '➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛㊀㊁㊂㊃㊄㊅㊆㊇㊈㊉ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ';
$fuhao .= '﹢﹣×÷±/=≌∽≦≧≒﹤﹥≈≡≠=≤≥<>≮≯∷∶∫∮∝∞∧∨∑∏∪∩∈∵∴⊥∥∠⌒⊙√∟⊿㏒㏑%‰⅟½⅓⅕⅙⅛⅔⅖⅚⅜¾⅗⅝⅞⅘≂≃≄≅≆≇≈≉≊≋≌≍≎≏≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≠≡≢≣≤≥≦≧≨≩⊰⊱⋛⋚∫∬∭∮∯∰∱∲∳%℅‰‱øØπ';
$str = str_replace($kong, '', $str);
$str = str_replace(str_split_unicode($fuhao), '', $str);
$filename = pathinfo($argv[1])["filename"];
$count = mb_strlen($str);
file_put_contents('./txt/' . $filename . '-' . $count . '.txt', $str);

$msg = '本次整理出 ' . $count . ' 个字' . PHP_EOL . '保存在.\txt\\' . $filename . '-' . $count . '.txt';
echo $msg;


/**
 * @param $str
 * @param int $length
 * @return array|array[]|false|string[]
 * 把字符串拆分为数组，支持中文等其它多字节语言
 */
function str_split_unicode($str, $length = 1)
{
    $tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
    if ($length > 1) {
        $chunks = array_chunk($tmp, $length);
        foreach ($chunks as $i => $chunk) {
            $chunks[$i] = join('', (array)$chunk);
        }
        $tmp = $chunks;
    }
    return $tmp;
}